{include file="public/header" type='pear-container'/}
<style>
    .layui-input-block {
        margin-left: 35px;
        min-height: 36px; 
    }
    .pear-btn-primary{
        width: 120px;
    }
    .layui-btn-primary{
        width: 120px;
        height: 36px; 
        margin-bottom: 5px;
    }
    @media (max-width:765px){
        .layui-btn-primary{
            
             float: right;
            margin-right: 35px;
        }
           
    }
    .page-title {
        font-size: 18px;
        margin: 5px;
        margin: 15px 37px;
        line-height: 60px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        color: inherit;
    }
    .update_tips {
        font-size: 13px;
        color: #666;
        font-weight: 600;
    }
    .update_conter {
        background: #f9f9f9;
        border-radius: 4px;
        padding: 20px;
        margin: 15px 37px;
        margin-top: 15px;
    }
</style>
<!-- 代 码 结 构 -->
<div class="layui-row layui-col-space10">
<div class="layui-card">
    <div class="layui-card-header">在线更新</div>
    <div class="layui-card-body">
        <form class="layui-form" action="javascript:void(0);" onsubmit="return false">
            <div class="layui-form-item">
                <?php if($update['code']==200){ ?>
                <h4 class="page-title" style="font-weight:300;">最新版本：{$update['version']}</h4>
                <?php }else{ ?>
                <h4 class="page-title" style="font-weight:300;">当前版本：{$ver}</h4>
                <?php } ?>
            </div>
            <div class="layui-form-item">
                <div class="update_conter" style="max-height: 300px;overflow: auto;">
                    <div class="update_tips">
                        <?php if($update['code']== 200){ ?>
                            {:html_entity_decode($update['updateMsg'])}
                        <?php }else{ ?>
                            {$update['msg']}
                        <?php } ?>
                            
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block" >
                    <?php if($update['code']==200){ ?>
                    <button class="pear-btn pear-btn-primary" lay-submit lay-filter="Update">更 新</button>
                    <?php }else{ ?>
                    <button class="pear-btn pear-btn-primary" lay-submit lay-filter="Check">检 测</button>
                    <?php } ?>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
    
</div>
<div class="layui-card">
    <div class="layui-card-header">手动更新</div>
    <div class="layui-card-body">
        <div class="layui-upload-drag" style="display: block;" id="ID-upload-drag">
            <i class="layui-icon layui-icon-upload"></i> 
            <div>点击上传，或将文件拖拽到此处</div>
            <div class="layui-hide" id="ID-upload-preview">
                <input class="upload">
            </div>
        </div>
    </div>
    
</div>
<div class="layui-card">
    <div class="layui-card-header">更新日志</div>
    <div class="layui-card-body layui-input-block">
        <div class="layui-timeline">
            <?php foreach ($update_info as $key => $value): ?>
                <div class="layui-timeline-item">
                    <i class="layui-icon layui-timeline-axis">&#xe63f;</i>
                    <div class="layui-timeline-content layui-text">
                        <h3 class="layui-timeline-title">{$value.version}</h3>
                        {:html_entity_decode($value['change_log'])}
                    </div>
                </div>
            <?php endforeach; ?>
        </div>
    </div>
</div>
</div>
{include file="public/footer"/}
<script>
layui.use(['form', 'button', 'popup','upload'], function() {
    let $ = layui.jquery;
    var form = layui.form;
    var button = layui.button;
    var popup = layui.popup;
    var upload = layui.upload;
    let MODULE_PATH = "{$Request.root}/Update";
     // 渲染
    upload.render({
      elem: '#ID-upload-drag',
      url: MODULE_PATH + '/upload', // 此处配置你自己的上传接口即可
      accept: 'file', // 普通文件
      done: function(res){
        if (res.code === 200) {
            layer.msg(res.msg, {
                icon: 1,
                time: 1000
            });
            setTimeout(function () {
                location.reload();
            }, 2000);
        } else {
            layer.msg(res.msg, {
                icon: 2,
                time: 1000
            });
        }
        }
    });

    form.on('submit(Update)', function (obj) {
         layer.closeAll();
            $.post('{$Request.root}/update/update_ver',
            function(data)
            {
                layer.alert(data.msg, function(index){
                    window.location.reload();
                });
                
                return false;
            });
    });

    form.on('submit(Check)', function (obj) {
        var index = layer.msg('正在检测中,请稍后...', {icon: 16, time: 3000});
        layer.close(index);
        layer.msg('正在检测请稍等片刻...', {
            icon: 6,
            time: 3000
        }, function(){
            $.post('{$Request.root}/update/check_ver',
            function(data)
            {
                layer.alert(data.msg, function(index){
                    window.location.reload();
                });
                
                return false;
            });
        });
        return false;
    });

})
</script>
</body>
</html>